home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************
- +
- + LEDA 2.1.1 11-15-1991
- +
- +
- + b_stack.h
- +
- +
- + Copyright (c) 1991 by Max-Planck-Institut fuer Informatik
- + Im Stadtwald, 6600 Saarbruecken, FRG
- + All rights reserved.
- +
- *******************************************************************************/
-
-
-
-
- #ifndef BSTACKH
- #define BSTACKH
-
- #include <LEDA/basic.h>
-
-
- //------------------------------------------------------------------------------
- // bounded stacks
- //
- // S. Naeher (1989)
- //
- //------------------------------------------------------------------------------
-
- #define b_stack(type) name2(type,b_stack)
-
- #define b_stackdeclare(type)\
- class b_stack(type) {\
- type* v;\
- int sz; \
- int t;\
- public:\
- \
- b_stack(type)(int n)\
- { if (n<1) error_handler(99,"b_stack: bad size");\
- sz = n;\
- t = -1;\
- v = new type[sz];\
- if (v==0) error_handler(99,"b_stack: out of memory");\
- }\
- \
- ~b_stack(type)() { delete[0] v; }\
- \
- int size() const { return t+1; }\
- int empty() const { return (t<0) ? true : false; }\
- \
- void push(type& a)\
- { t++;\
- if (t==sz) error_handler(99,"b_stack overflow");\
- v[t] = a;\
- }\
- \
- type pop()\
- { if (t<0) error_handler(99,"b_stack underflow");\
- return v[t--];\
- }\
- \
- type top() const \
- { if (t<0) error_handler(99,"b_stack empty");\
- return v[t];\
- }\
- \
- void clear() { t = -1; }\
- };
-
-
- #endif
-